package top.code.attend.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.code.attend.entity.Attend;
import top.code.attend.service.AttendService;
import top.code.attend.viewObject.QueryCondition;
import top.code.common.utils.PageQueryBean;
import top.code.user.entity.User;

import javax.servlet.http.HttpSession;

/**
 * Created by setsun on 2017/9/25.
 */
@Controller
@RequestMapping("attend")
public class AttendController {
    @Autowired
    private AttendService attendService;

    @RequestMapping
    public String toAttend(){
        return "attend";
    }

    @RequestMapping("/sign")
    @ResponseBody
    public String signAttend(@RequestBody Attend attend) throws Exception {
        attendService.signAttend(attend);
        return "succ";
    }

    /**
    *@Author benson {www.honey520.com}
    *@Date 2017/9/26 15:06
    *@Description 查询数据分页
    */
    @RequestMapping("/attendList")
    @ResponseBody
    public PageQueryBean listAttend(QueryCondition condition , HttpSession session){
       User user = (User) session.getAttribute("userinfo");
       String[] rangeDate = condition.getRangeDate().split("/");    //分割日期
        condition.setStartDate(rangeDate[0]);
        condition.setEndDate(rangeDate[1]);
        condition.setUserId(user.getId());
        PageQueryBean result = attendService.listAttend(condition);
        return result;
    }

}
